package com.sk.bilibili.model.fragment.main;

import android.content.Context;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.LookLater;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.LookLaterMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.main.LaterFragment;
import com.sk.bilibili.view.fragment.main.SaveFragment;

import java.util.List;

import okhttp3.OkHttpClient;

public class LaterModel extends BaseModel<LaterFragment> {

    @Autowired
    LookLaterMapper lookLaterMapper;
    private int page=1;
    private int size=10;

    @Override
    public void loadData() {
        RequestUtils.process(lookLaterMapper.page(page, size), lookLaterPage -> {
            view.loadDataSuccess(lookLaterPage.getRecords());
            page++;
        });
    }

    public void removeOver() {
        RequestUtils.process(lookLaterMapper.removeOver(), unused -> refresh());
    }

    public void refresh() {
        page=1;
        RequestUtils.process(lookLaterMapper.page(page, size), lookLaterPage -> {
            view.refreshSuccess(lookLaterPage.getRecords());
            view.setNum(lookLaterPage.getTotal());
            page++;
        });
    }

}